<template>
  <el-form
    label-width="auto"
    label-position="top"
    class="demo-ruleForm"
    style="margin-top: 20px"
  >
    <el-form-item label="十、专家组名单">
      <el-select v-model="ruleForm.expertIds" multiple placeholder="请选择">
        <el-option
          v-for="item in users"
          :key="item.id"
          :label="item.nickname"
          :value="item.id"
        />
      </el-select>
    </el-form-item>
  </el-form>
</template>

<script setup>
  import { getAllUser } from '@/api/system/user'

  const $baseMessage = inject('$baseMessage')

  const users = ref([])

  const ruleForm = reactive({
    expertIds: [],
  })

  const getFormData = () => {
    for (const key in ruleForm) {
      if (!ruleForm[key].length) {
        $baseMessage('请填写专家组名单', 'error')
        return false
      }
    }
    return ruleForm
  }

  const getUserList = () => {
    getAllUser().then((res) => {
      if (res.code == 0 || res.code == 200) {
        users.value = res.data || []
      }
    })
  }

  const setFormData = (data) => {
    const getType = route.query.getType || 2
    ruleForm.expertIds = getType == 2 ? data.baseInfo.expertIds : data.expertIds
  }

  defineExpose({ getFormData, setFormData })

  getUserList()
</script>

<style lang="scss" scoped></style>
